#ifndef __WEB_PAGE_QUERY_H__
#define __WEB_PAGE_QUERY_H__
//设计网页查询主要类

#include"SplitToolJieba.h"
#include"WebPage.h"
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<queue>
#include<algorithm>
#include<fstream>

using std::vector;
using std::string;
using std::map;
using std::unordered_map;
using std::pair;
using std::set;
using std::priority_queue;
using std::ifstream;


struct getmyresult
{
    double second;
    int first;
};
namespace std
{
    template<>
    struct less<getmyresult>
    {
        bool operator()(const getmyresult& lhs ,const getmyresult& rhs )
        {
            if(lhs.second>rhs.second)
            {
            return true;
            }
            else if(lhs.second==rhs.second)
            {
                return true;
            }
            return false;
        }
    };
}

class WebPageQuery
{
    public:
    //构造并预加载本地内容
    WebPageQuery(SplitTool*);
    
    //传入关键词，并依据索引检查_inverindex
    nlohmann::json doQuery(const string & key);

    //初始化
    void init();

    //根据拿到结果集的优先级队列找到前10个网页并读取对应文件到_pages里面
    void getpage(priority_queue<getmyresult>&  lhs);

    //push_art放入vector
    void push_art(getmyresult& lhs);


    private:
    //存储经过向量计算之后的相关网页
    vector<WebPage> _pages;

    //读取本地的偏移库
    map<int,pair<int,int>> _offsetlib;

    //读取倒排索引
    unordered_map<string , vector<pair<int ,double>>> _invertindex;

    //结巴工具指针
    SplitTool* _jieba;

    //存储中文停用词
    set<string> _stoplib;

    ifstream _ifs;

};

#endif
